
function Cons (car, cdr)
{
    this.type="CONS";
    this.car = car;
    this.cdr = cdr;
}

function cons (car, cdr)
{
    return new Cons(car,cdr);
}

function consp (x)
{
    return typep(x,"CONS");
}

function atom(x)
{
    if (!x || x.type != "CONS")
	return true;
    return false;
}

function first (list)
{
    if (!list)
	return null;
    return list.car;
}

function rest (list)
{
    if (!list)
	return null;
    return list.cdr;
}

function second(list)
{
    return first(rest(list));
}

function third(list)
{
    return first(rest(rest(list)));
}

function map (fn,list)
{
    if (list == null)
	return null;
    return cons(fn(first(list)),map(fn,rest(list)));
}

